package connect4client.core;

import java.util.*;


public class GameManager {
	
	/**
	 * Adds an invitation to the pendingInvitation list.
	 * 
	 * @param invitation The Invitation to be added.
	 */
	public synchronized void addInvitation(int id,Invitation invitation) {
		pendingInvitations.put(id, invitation);
	}
	
	/**
	 * Returns the Invite with the given ID.
	 * 
	 * @param id The ID of the Invite to obtain.
	 * @return The Invite with the given ID.
	 */
	public synchronized Invitation getInvitationByID(int id) {
		return this.pendingInvitations.get(id);
	}
		
	/**
	 * Removes an Invitation with the given ID.
	 * 
	 * @param id The ID of the Invite to be removed.
 	 */
	public synchronized void removeInvitation(int id){
		this.pendingInvitations.remove(id);
	}
	
	/**
	 * Removes a Match with the given ID.
	 * 
	 * @param id The ID of the Match to be removed.
 	 */
	public synchronized void removeMatch(int id){
		this.matches.remove(new Integer(id));
	}
	
	
	/**
	 * Starts a new game.
	 * 
	 * @param id The id of the Match given by the server.
	 * @param challenger The object who represents the challenger. 
	 */	
	public void createMatch(int id){
		this.matches.add(id);
	}
		
	
	public synchronized boolean containsMatch(int matchId){
		return this.matches.contains(matchId);
	}
	
	
	public synchronized List<String> getGames() {
		return this.games;
	}

	
	// Existing Games in the server
	private List<String> games = new ArrayList<String>();
	
	// Started matches.
	private List<Integer> matches = new ArrayList<Integer>();
	
	// Invitations sent but not yet answered.
	private Map<Integer, Invitation> pendingInvitations = new HashMap<Integer, Invitation>();
}


